In [1]:
import json
import re

In [2]:
with open('../catalogs/json/gabi_2014.json') as fp:
    G = json.load(fp)

In [3]:
G.viewkeys()


Out[3]:
dict_keys([u'catalogReference', u'archives', u'catalogType'])

In [4]:
## G['archives']  # this will generate thousands of lines of output and chokes the notebook.
## do this instead:
type(G['archives'])


Out[4]:
list

In [5]:
len(G['archives'])


Out[5]:
1

In [6]:
A = G['archives'][0]
type(A)


Out[6]:
dict

In [7]:
A.keys()


Out[7]:
[u'processes',
 u'quantities',
 u'exchanges',
 u'flows',
 u'dataSourceReference',
 u'dataSourceType']

In [8]:
A['exchanges'][:10]


Out[8]:
[{u'direction': u'Output',
  u'flow': u'flows/d71fef59-2e93-450f-b18f-72981f58e312',
  u'process': u'processes/c0f149de-616e-4a01-a670-0cc4891b61c7'},
 {u'direction': u'Output',
  u'flow': u'flows/d71fef59-2e93-450f-b18f-72981f58e312',
  u'process': u'processes/bb572f9f-7835-4246-bcd0-68f60a63594a'},
 {u'direction': u'Output',
  u'flow': u'flows/8c5fd1a8-a1d6-42f8-acd6-4e5ae7ed8397',
  u'process': u'processes/4c322302-d16e-4ae9-a611-c161bfaf3427'},
 {u'direction': u'Output',
  u'flow': u'flows/d71fef59-2e93-450f-b18f-72981f58e312',
  u'process': u'processes/b6b068e4-7ac3-43ab-9789-8db7d4c80a13'},
 {u'direction': u'Output',
  u'flow': u'flows/aaf98aed-97e6-4ab1-9b20-acc61bc8385b',
  u'process': u'processes/dd66e40d-0616-4a0b-bf50-54515a4d8911'},
 {u'direction': u'Output',
  u'flow': u'flows/fa4d0c5b-122a-44db-b6c3-ce03a0c6f794',
  u'process': u'processes/9fa3c422-f097-4bbb-a204-144f379597b5'},
 {u'direction': u'Output',
  u'flow': u'flows/890a70b7-b677-4e2a-8a1b-7d017e0a10ae',
  u'process': u'processes/dbaa8656-4e0b-40cb-af20-1496ade0ec28'},
 {u'direction': u'Output',
  u'flow': u'flows/76013e3e-e074-4452-b1da-7d47842345a8',
  u'process': u'processes/27b2f25c-ccec-43cf-97b9-bc97f0f95f49'},
 {u'direction': u'Output',
  u'flow': u'flows/890a70b7-b677-4e2a-8a1b-7d017e0a10ae',
  u'process': u'processes/b07255b0-da57-4db4-a1e7-7f53f3ce536a'},
 {u'direction': u'Output',
  u'flow': u'flows/890a70b7-b677-4e2a-8a1b-7d017e0a10ae',
  u'process': u'processes/f63347f7-3180-412c-95de-b3d480822693'}]

In [9]:
te = [flow for flow in A['flows'] if re.search('Thermal', flow['tags']['Name'])]

In [10]:
te


Out[10]:
[{u'ReferenceQuantity': u'flowproperties/93a60a56-a3c8-11da-a746-0800200c9a66',
  u'dataSetReference': u'flows/fe2304b5-b6eb-43a6-a2ad-6343d5600bb6',
  u'entityType': u'flow',
  u'tags': {u'CasNumber': u'',
   u'Comment': u'',
   u'Compartment': [u'Valuable substances',
    u'Energy carrier',
    u'Thermal energy'],
   u'Name': u'Thermal energy (MJ)'}},
 {u'ReferenceQuantity': u'flowproperties/93a60a56-a3c8-11da-a746-0800200c9a66',
  u'dataSetReference': u'flows/7c5c690c-b58b-478d-8df8-6cc9520f32c1',
  u'entityType': u'flow',
  u'tags': {u'CasNumber': u'',
   u'Comment': u'',
   u'Compartment': [u'Valuable substances',
    u'Energy carrier',
    u'Thermal energy'],
   u'Name': u'Thermal energy from storage (MJ)'}},
 {u'ReferenceQuantity': u'flowproperties/93a60a56-a3c8-11da-a746-0800200c9a66',
  u'dataSetReference': u'flows/ab09db3b-9577-4fbf-b72b-96404245faf6',
  u'entityType': u'flow',
  u'tags': {u'CasNumber': u'',
   u'Comment': u'',
   u'Compartment': [u'Valuable substances',
    u'Energy carrier',
    u'Thermal energy'],
   u'Name': u'Thermal energy from solar (MJ)'}}]

In [28]:
te[0]


Out[28]:
{u'ReferenceQuantity': u'flowproperties/93a60a56-a3c8-11da-a746-0800200c9a66',
 u'dataSetReference': u'flows/fe2304b5-b6eb-43a6-a2ad-6343d5600bb6',
 u'entityType': u'flow',
 u'tags': {u'CasNumber': u'',
  u'Comment': u'',
  u'Compartment': [u'Valuable substances',
   u'Energy carrier',
   u'Thermal energy'],
  u'Name': u'Thermal energy (MJ)'}}

In [11]:
[q for q in A['quantities'] if q['dataSetReference'] == te[0]['ReferenceQuantity']]


Out[11]:
[{u'ReferenceUnit': u'unitgroups/93a60a57-a3c8-11da-a746-0800200c9a66',
  u'dataSetReference': u'flowproperties/93a60a56-a3c8-11da-a746-0800200c9a66',
  u'entityType': u'quantity',
  u'tags': {u'Comment': u'Reference Flow Property Data Set of the International Reference Life Cycle Data System (ILCD).',
   u'Name': u'Net calorific value',
   u'UnitConversion': {u'GJ': 1000.0,
    u'J': 1e-06,
    u'MJ': 1.0,
    u'MWh': 3600.0,
    u'TCE': 29307.6,
    u'TOE': 41868.0,
    u'btu': 0.001055056,
    u'kWh': 3.6,
    u'kcal': 0.0041867}}}]

In [13]:
solar_processes = [p['process'] for p in A['exchanges'] if p['flow'] == te[2]['dataSetReference']]

In [14]:
solar_processes


Out[14]:
[u'processes/d3771dd6-6344-468a-a8df-593d367395e7',
 u'processes/1e83f559-7a4e-42d5-aa5b-36a46449df69',
 u'processes/af5240f1-8525-47cb-baaa-2c9ab908492e']

In [15]:
[p for p in A['processes'] if p['dataSetReference'] in solar_processes ]


Out[15]:
[{u'ReferenceExchange': u'Output: flows/ab09db3b-9577-4fbf-b72b-96404245faf6',
  u'dataSetReference': u'processes/af5240f1-8525-47cb-baaa-2c9ab908492e',
  u'entityType': u'process',
  u'tags': {u'Classifications': [u'Processes',
    u'Construction industry',
    u'Building services engineering',
    u'Use building services engineering',
    u'Heating'],
   u'Comment': u'The data set covers all relevant process steps / technologies over the supply chain of the represented cradle to gate inventory with a good overall data quality. The inventory is mainly based on industry data and is completed, where necessary, by secondary data. This data set is based on primary data from internationally adopted production processes, connected with regional precursor chains.',
   u'Name': u'Tube collector (Big plant > 500m2)',
   u'SpatialScope': u'EU-27',
   u'TemporalScope': u'interval(2013, 2016)'}},
 {u'ReferenceExchange': u'Output: flows/ab09db3b-9577-4fbf-b72b-96404245faf6',
  u'dataSetReference': u'processes/d3771dd6-6344-468a-a8df-593d367395e7',
  u'entityType': u'process',
  u'tags': {u'Classifications': [u'Processes',
    u'Construction industry',
    u'Building services engineering',
    u'Use building services engineering',
    u'Heating'],
   u'Comment': u'The data set covers all relevant process steps / technologies over the supply chain of the represented cradle to gate inventory with a good overall data quality. The inventory is mainly based on industry data and is completed, where necessary, by secondary data.',
   u'Name': u'Flat collector (Big plant > 500m2) (Use)',
   u'SpatialScope': u'CN',
   u'TemporalScope': u'interval(2013, 2016)'}},
 {u'ReferenceExchange': u'Output: flows/ab09db3b-9577-4fbf-b72b-96404245faf6',
  u'dataSetReference': u'processes/1e83f559-7a4e-42d5-aa5b-36a46449df69',
  u'entityType': u'process',
  u'tags': {u'Classifications': [u'Processes',
    u'Construction industry',
    u'Building services engineering',
    u'Use building services engineering',
    u'Heating'],
   u'Comment': u'The data set covers all relevant process steps / technologies over the supply chain of the represented cradle to gate inventory with a good overall data quality. The inventory is mainly based on industry data and is completed, where necessary, by secondary data. This data set is based on primary data from internationally adopted production processes, connected with regional precursor chains.',
   u'Name': u'Flat collector (Big plant > 500m2)',
   u'SpatialScope': u'EU-27',
   u'TemporalScope': u'interval(2013, 2016)'}}]

In [16]:
len([process for process in A['processes'] if process['ReferenceExchange'] == 'Output: %s' % te[0]['dataSetReference']])


Out[16]:
230

In [17]:
from collections import Counter

In [18]:
outflow = Counter()
for p in A['processes']:
    outflow[p['ReferenceExchange']] +=1

In [19]:
outflow.most_common(50)


Out[19]:
[(u'Output: flows/d71fef59-2e93-450f-b18f-72981f58e312', 622),
 (u'Output: flows/890a70b7-b677-4e2a-8a1b-7d017e0a10ae', 413),
 (u'Output: flows/fe2304b5-b6eb-43a6-a2ad-6343d5600bb6', 230),
 (u'Output: flows/e9fd08fb-8067-4d90-91e3-4c92fc1803f7', 127),
 (u'Input: flows/e0c2b408-7dca-41de-ad53-2d7975838e87', 59),
 (u'Input: flows/55a81a3f-4639-4be6-99a0-22586cbc1e84', 54),
 (u'Input: flows/64876ac6-a289-45f8-b94d-d720c93e2830', 50),
 (u'Output: flows/9106196a-8660-41a3-895b-0cddbbe9ca5b', 48),
 (u'Output: flows/5cd49049-83ce-4a48-8c23-18a27de88a83', 21),
 (u'Output: flows/55a4c166-2eb6-43a3-9a13-2e4f2c4fee60', 18),
 (u'Output: flows/81aed24e-a316-485d-b6c2-7cbc316b2d28', 14),
 (u'Output: flows/830b6968-5b87-42d2-b679-03973197cfa6', 13),
 (u'Output: flows/cc42cd54-36f3-4b6c-930a-c47144607c12', 12),
 (u'Output: flows/b909af97-bff5-43e1-87be-9993589a4387', 12),
 (u'Output: flows/9b5fb8b6-a8f4-48d5-b912-56c65c0cc263', 12),
 (u'Output: flows/efa69527-5e73-4485-b95f-91fcbe097f3e', 12),
 (u'Input: flows/71d1241f-fb2b-4774-9c17-18f19955c2db', 11),
 (u'Output: flows/cf2bd799-5a6a-48ba-9d12-9005fc6b8ac5', 9),
 (u'Output: flows/fa4d0c5b-122a-44db-b6c3-ce03a0c6f794', 9),
 (u'Output: flows/faf3163d-6b99-4578-9bed-c44d7eaca028', 9),
 (u'Output: flows/235ddf08-254c-45be-ab34-c2569b2f68ca', 9),
 (u'Output: flows/8e1e39c0-11ef-4607-85f0-157ae68f6c63', 9),
 (u'Output: flows/53afe53a-7bbc-4b82-8e39-df2c6bbb2c46', 8),
 (u'Output: flows/23e5fea5-d83a-4d27-9cb2-2907f715f4ab', 8),
 (u'Output: flows/9f723736-35c3-4218-8dbe-a1331f56be46', 8),
 (u'Output: flows/ef0193ef-fd64-4fa5-9948-5365b30f36bd', 8),
 (u'Output: flows/d8a11424-0089-465b-8e5d-40aef78f1fe7', 8),
 (u'Output: flows/a9eed32e-1dd7-412c-8972-8aa730131db7', 8),
 (u'Output: flows/ee2fff3b-78dd-4fa3-b346-af7130d5b34c', 8),
 (u'Output: flows/b53fc253-533d-4da1-aad3-dc092902e2fe', 8),
 (u'Output: flows/ea9cd04e-cb31-467b-9311-d2a2e43f55f4', 7),
 (u'Output: flows/8c5fd1a8-a1d6-42f8-acd6-4e5ae7ed8397', 7),
 (u'Output: flows/ae206e6f-e4f5-4dbf-8de7-42576f6da892', 7),
 (u'Output: flows/5a740d05-5a1c-42f4-8b5b-8680dfca6636', 7),
 (u'Output: flows/9556b2dd-a149-480e-96bc-d2678947ffd9', 7),
 (u'Output: flows/917ee290-097e-443d-aa94-1e61e06f8f24', 7),
 (u'Output: flows/2126a80d-1cd0-46e4-8f30-341bd20a1d64', 6),
 (u'Output: flows/644c2d89-0efb-45e2-a8a7-6ead451c1b84', 6),
 (u'Output: flows/c707e768-2a44-4b33-8218-e8dcdb345132', 6),
 (u'Output: flows/c13fc156-d6f2-40b7-acc1-93ce441c348f', 6),
 (u'Output: flows/0e63e411-090d-4b39-9606-f467816b734c', 6),
 (u'Input: flows/53d51aa1-f1ae-4ad5-8a03-2caba9f41e43', 6),
 (u'Output: flows/4ccd63df-b0eb-4a78-a07f-9d5e555dc7c9', 6),
 (u'Output: flows/f46cd45b-b457-41f3-bd08-1ab41bd796e5', 5),
 (u'Output: flows/4d464b0c-62ad-4ec3-b870-eb2e1048d3fb', 5),
 (u'Output: flows/4e5197c4-ffce-4f2d-a648-ebb25bb63748', 5),
 (u'Output: flows/b5047c96-7f4d-46e5-8424-6f43e62e2fdd', 5),
 (u'Output: flows/f5458338-7c8d-4b77-815b-ef2a2df69ee8', 5),
 (u'Output: flows/311a6556-602a-4bd7-bb7e-8fdcd15138b0', 5),
 (u'Output: flows/577f1bae-3168-4761-9852-8dbf555a0365', 5)]

In [20]:
def flow_from_exchange(ref):
    return re.match('^(((In)|(Out))put: )?(.*)$', ref).groups()[-1]

In [21]:
def flow_name(ref):
    return [f['tags']['Name'] for f in A['flows'] if f['dataSetReference'] == flow_from_exchange(ref)]

In [22]:
['%3d: %s' % (j, flow_name(i)) for i, j in outflow.most_common(5)]


Out[22]:
["622: [u'Steam (MJ)']",
 "413: [u'Electricity']",
 "230: [u'Thermal energy (MJ)']",
 "127: [u'Cargo']",
 " 59: [u'Aluminium scrap']"]

59 processes whose reference exchange is an input of Alumin[i]um scrap!!?


In [23]:
['%10s %s' %('[' + p['tags']['SpatialScope'] +']', p['tags']['Name']) for p in A['processes'] if p['ReferenceExchange'] == outflow.most_common(5)[4][0]]


Out[23]:
[u'   [EU-15] Auto transmissions - scrap credit (open loop)',
 u'      [US] Aluminium foil - scrap credit (open loop)',
 u'      [US] Aluminium turnings - scrap credit (open loop)',
 u'   [EU-15] Paperbacked aluminium foil - scrap credit (open loop)',
 u'   [EU-15] Clean painted aluminium sheets - scrap credit (open loop)',
 u'      [US] Low grade irony aluminium - scrap credit (open loop)',
 u'      [US] Loose used beverage cans (UBC) - scrap credit (open loop)',
 u'   [EU-15] Old mixed aluminium - scrap credit (open loop)',
 u'   [EU-15] Cast aluminium - scrap credit (open loop)',
 u'      [CN] Recycling potential aluminium (sheet and profiles)',
 u'      [US] Auto transmissions - scrap credit (open loop)',
 u'   [EU-15] Painted, insulated aluminium sheets - scrap credit (open loop)',
 u'   [EU-15] Coated aluminium - scrap credit (open loop)',
 u'      [US] Baled used beverage cans (UBC) - scrap credit (open loop)',
 u'   [EU-15] Aluminium auto rads - scrap credit (open loop)',
 u'   [EU-15] Aluminium auto wheels - scrap credit (open loop)',
 u'   [EU-15] Baled used beverage cans (UBC) - scrap credit (open loop)',
 u'      [US] Paperbacked aluminium foil - scrap credit (open loop)',
 u'      [US] Low copper aluminium - scrap credit (open loop)',
 u'      [US] New beverage cans stock - scrap credit (open loop)',
 u'      [US] Mixed irony aluminium - scrap credit (open loop)',
 u'      [US] Clean painted aluminium sheets - scrap credit (open loop)',
 u'   [EU-15] Mixed irony aluminium - scrap credit (open loop)',
 u'      [US] Utensil aluminium - scrap credit (open loop)',
 u'   [EU-15] Aluminium foil - scrap credit (open loop)',
 u'      [US] Insulated aluminium wire - scrap credit (open loop)',
 u'   [EU-15] Bare aluminium wire - scrap credit (open loop)',
 u'      [US] Aluminium auto rads - scrap credit (open loop)',
 u'      [US] Remelt aluminium ingots - credit (open loop)',
 u'      [US] Aluminium nodules - scrap credit (open loop)',
 u'      [US] Briquetted used beverage cans (UBC) - scrap credit (open loop)',
 u'   [EU-15] Remelt aluminium sows - credit (open loop)',
 u'      [US] Aluminium auto fragments - scrap credit (open loop)',
 u'   [EU-15] Aluminium nodules - scrap credit (open loop)',
 u'   [EU-15] Aluminium auto fragments - scrap credit (open loop)',
 u'   [EU-15] Low copper aluminium - scrap credit (open loop)',
 u'      [US] Painted, insulated aluminium sheets - scrap credit (open loop)',
 u'   [EU-15] Low grade irony aluminium - scrap credit (open loop)',
 u'   [EU-15] Insulated aluminium wire - scrap credit (open loop)',
 u'      [US] Old mixed aluminium - scrap credit (open loop)',
 u'      [US] Supported aluminium cable - scrap credit (open loop)',
 u'   [EU-15] Remelt aluminium ingots - credit (open loop)',
 u'      [US] Aluminium auto wheels - scrap credit (open loop)',
 u'      [US] Aluminium litho sheets - scrap credit (open loop)',
 u'      [US] Cast aluminium - scrap credit (open loop)',
 u'   [EU-15] New beverage cans stock - scrap credit (open loop)',
 u'   [EU-15] Shredded used beverage cans (UBC) - scrap credit (open loop)',
 u'      [US] Remelt aluminium sows - credit (open loop)',
 u'      [US] Coated aluminium - scrap credit (open loop)',
 u'   [EU-15] Loose used beverage cans (UBC) - scrap credit (open loop)',
 u'      [US] Shredded used beverage cans (UBC) - scrap credit (open loop)',
 u'   [EU-15] Utensil aluminium - scrap credit (open loop)',
 u'   [EU-15] Supported aluminium cable - scrap credit (open loop)',
 u'      [US] Bare aluminium wire - scrap credit (open loop)',
 u'   [EU-15] Briquetted used beverage cans (UBC) - scrap credit (open loop)',
 u'   [EU-15] Aluminium extrusions - scrap credit (open loop)',
 u'   [EU-15] Aluminium turnings - scrap credit (open loop)',
 u'   [EU-15] Aluminium litho sheets - scrap credit (open loop)',
 u'      [US] Aluminium extrusions - scrap credit (open loop)']